//
//  TwoToOne.m
//  xCode7网络请求封装
//
//  Created by dllo on 15/9/30.
//  Copyright © 2015年 S1mpl3. All rights reserved.
//

#import "TwoToOne.h"


@implementation TwoToOne

+(void)getDataByString:(NSString *)string BodyString:(NSDictionary *)bodyDic WithDataBlock:(MyBlock)block{
    
    if ([string hasPrefix:@" "]) {
         string = [string substringFromIndex:1];
        string = [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:string]];
        

        
    }
    else
    {
        string = [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    }
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    //设置允许请求的类别

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html", @"application/javascript", @"text/js", nil];
    if (!bodyDic) {
        //如果bodyDic为空就执行get请求
        [manager GET:string parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
            
                      block(responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//            NSLog(@"%@", error);
        }];
    }else{
        [manager POST:string parameters:bodyDic success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
            block(responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//            NSLog(@"%@", error);
        }];
    }

}


@end
